package com.woniu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.entity.Auth;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
public interface AuthMapper extends BaseMapper<Auth> {
    @Results(id = "authMap", value = {
            @Result(id = true, property = "authId", column = "auth_id"),
            @Result(property = "authName", column = "auth_name"),
            @Result(property = "authCode", column = "auth_code"),
            @Result(property = "authPid", column = "auth_pid"),
            @Result(property = "authStatus", column = "auth_status"),
            @Result(property = "subAuth", column = "auth_id", javaType = List.class,
                    many = @Many(select = "com.woniu.mapper.AuthMapper.getByPid", fetchType = FetchType.LAZY))
    })
    @Select("select * from auth where auth_id = #{id}")
    Auth getById(int id);



    @Select("select * from auth a,role_mind_auth ra where a.auth_id = ra.auth_id and ra.role_id = #{roleId}")
    @ResultMap("authMap")
    List<Auth> getByRoleId(int roleId);


    @Select("select * from auth where auth_pid = #{id}")
    @ResultMap("authMap")
    List<Auth> getByPid(int id);

    @Select("select * from auth where auth_status = 'y' and auth_pid = 0")
    @ResultMap("authMap")
    List<Auth> getParentAccess();
}
